from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout

class MainScreen(Screen):
    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)
        layout = BoxLayout(orientation='vertical')
        button = Button(text='Go to Second Screen')
        button.bind(on_press=self.go_to_second_screen)
        layout.add_widget(button)
        self.add_widget(layout)

    def go_to_second_screen(self, instance):
        self.manager.current = 'second'

class SecondScreen(Screen):
    def __init__(self, **kwargs):
        super(SecondScreen, self).__init__(**kwargs)
        layout = BoxLayout(orientation='vertical')
        button = Button(text='Go to Main Screen')
        button.bind(on_press=self.go_to_main_screen)
        layout.add_widget(button)
        self.add_widget(layout)

    def go_to_main_screen(self, instance):
        self.manager.current = 'main'

class MyApp(App):
    def build(self):
        # 创建屏幕管理器
        sm = ScreenManager()
        sm.add_widget(MainScreen(name='main'))
        sm.add_widget(SecondScreen(name='second'))
        return sm

if __name__ == '__main__':
    MyApp().run()